Skip to content

[codex] fix remote terminal live event updates#2805

Draft
SunkenInTime wants to merge 1 commit into
pingdotgg:mainfrom
SunkenInTime:codex/terminal-live-event-stream
Draft

[codex] fix remote terminal live event updates#2805
SunkenInTime wants to merge 1 commit into
pingdotgg:mainfrom
SunkenInTime:codex/terminal-live-event-stream

Conversation

@SunkenInTime
Copy link
Copy Markdown

@SunkenInTime SunkenInTime commented May 25, 2026

Summary

Fixes a remote terminal rendering issue where terminal input/output can remain invisible until the user switches terminal tabs. The active terminal viewport now owns a live terminal event subscription in addition to the existing environment-level terminal event store path.

Root Cause

Terminal open/snapshot calls and terminal live events travel through different client paths:

  • terminal.open returns the server-side terminal history snapshot.
  • subscribeTerminalEvents pushes incremental TerminalEvent updates into the client store.
  • TerminalViewport previously depended on the environment-level subscription populating useTerminalStateStore, then rendered from that store.

When the environment-level terminal event path is stale, gated, or otherwise fails to deliver remote events to the store, the server can still receive PTY output and persist history, but the visible xterm does not receive incremental updates. Switching terminal tabs remounts/reopens the terminal and repaints from the snapshot, making the buffered input/output appear all at once.

Changes

  • Add a viewport-owned api.terminal.onEvent subscription inside TerminalViewport.
  • Filter live terminal events to the active threadId and terminalId before applying them to xterm.
  • De-dupe terminal events so the new viewport-owned stream and the existing store-backed stream can both be active without double-writing output.
  • Reuse the existing terminal input helper for terminal.write error handling.
  • Add browser test coverage proving that output emitted through the viewport-owned terminal event stream is written to xterm.

User Impact

This keeps active remote terminal panes live even when the broader environment terminal event/store path does not update promptly. In the reported Mac-to-Windows remote case, this fixes commands and results not appearing until switching terminal tabs.

Validation

  • bun run fmt apps/web/src/components/ThreadTerminalDrawer.tsx apps/web/src/components/ThreadTerminalDrawer.browser.tsx
  • bun run test -- src/components/ThreadTerminalDrawer.test.ts
  • bun run test -- src/environments/runtime/service.test.ts
  • bun run test:browser -- src/components/ThreadTerminalDrawer.browser.tsx
  • bun run typecheck
  • git diff --check

Also manually tested against a Mac client connected to a Windows remote server matching 0.0.25-nightly.20260515.295; the reporter confirmed terminal updates now appear live instead of only after tab switching.

Note

Fix live terminal event updates in TerminalViewport for remote terminals

  • TerminalViewport now subscribes to api.terminal.onEvent and applies live output events to the terminal for the active thread/terminal, with cleanup on unmount.
  • Adds deduplication via terminalEventDedupeKey, tracking up to 500 applied event keys to prevent duplicate writes.
  • Refactors terminal open input construction and input sending into helpers without behavioral changes.
  • Adds browser tests verifying that viewport-owned terminal event stream output is written to the terminal via a new terminalWriteSpy and mock event emitter.

Macroscope summarized 649c243.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ac0daa27-9aca-413a-ae2a-db57b4e0f6c6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant